package DesignPattern.Singleton;

/**
 * @Author self
 * @Date 2024/8/11 17:37
 */

/*
通过同步方法确保线程安全，但性能可能受到影响。
*/

public class SingletonLanHanThreadSafe {
    private static SingletonLanHanThreadSafe instance;

    private SingletonLanHanThreadSafe() {}

    // 使用 synchronized 关键字保证线程安全
    public static synchronized SingletonLanHanThreadSafe getInstance() {
        if (instance == null) {
            instance = new SingletonLanHanThreadSafe();
        }
        return instance;
    }
}
